package com.yc.shadowdemo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.Toast
import com.tencent.shadow.dynamic.host.EnterCallback
import com.yc.shadowdemo.demo.TestGlideActivity
import com.yc.shadowdemo.demo.TestNetActivity
import com.yc.shadowdemo.demo.TestViewBindingActivity
import com.yc.shadowdemo.plugin.YcMainPluginProcessService
import com.yc.shadowdemo.plugin.YcPluginInit
import com.yc.shadowdemo.ui.WelcomeActivity

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        findViewById<Button>(R.id.btnFinish).setOnClickListener {
            startActivity(Intent(this, WelcomeActivity::class.java))
        }
        findViewById<Button>(R.id.btnGlideTest).setOnClickListener {
            startActivity(Intent(this, TestGlideActivity::class.java))
        }
        findViewById<Button>(R.id.btnNetTest).setOnClickListener {
            startActivity(Intent(this, TestNetActivity::class.java))
        }
        findViewById<Button>(R.id.btnViewBindingTest).setOnClickListener {
            startActivity(Intent(this, TestViewBindingActivity::class.java))
        }
        findViewById<Button>(R.id.btnStart).setOnClickListener {
            Toast.makeText(this,"启动插件中...",Toast.LENGTH_LONG).show()
            start2()
        }


    }

    private fun start2() {
        /**
         * @param context context
         * @param formId  标识本次请求的来源位置，用于区分入口
         * @param bundle  参数列表, 建议在参数列表加入自己的验证
         * @param callback 用于从PluginManager实现中返回View
         */
        val bundle = Bundle()
        // 插件 zip，这几个参数也都可以不传，直接在 PluginManager 中硬编码
        bundle.putString(YcPluginHostConstant.ToManagerKey.KEY_CHILD_ZIP_PATH, YcPluginHostConstant.ChildZipPath.MODULE_1)
        // partKey 每个插件都有自己的 partKey 用来区分多个插件，如何配置在下面讲到
        // 用于manager层的bindPluginProcessService("com.yc.createlib.plugin.YcMainPluginProcessService（服务类名）") 区分绑定的服务
        bundle.putString(YcPluginHostConstant.ToManagerKey.KEY_CHILD_PART_KEY, YcPluginHostConstant.ChildZipPath.MODULE_1_KEY)
        // 路径举例：com.google.samples.apps.sunflower.GardenActivity
        bundle.putString(YcPluginHostConstant.ToManagerKey.KEY_START_ACTIVITY_CLASSNAME, YcPluginHostConstant.ChildZipPath.MODULE_1_ACTIVITY_NAME)
        bundle.putString(YcPluginHostConstant.ToManagerKey.KEY_TO_ACTIVITY_SERVICE_NAME, YcMainPluginProcessService.SERVICE_NAME)

        // 要传入到插件里的参数
        bundle.putBundle(YcPluginHostConstant.ToManagerKey.KEY_TO_ACTIVITY_BUNDLE, Bundle().apply {
            putString("key_data", "测试下发送数据")
        })

        YcPluginInit.mInstance.mPluginManager.enter(this, YcPluginHostConstant.MANAGER_FROM_ID, bundle, object : EnterCallback {
            override fun onShowLoadingView(view: View?) {
            }

            override fun onCloseLoadingView() {
            }

            override fun onEnterComplete() {

            }

        });
    }

}